Page({

  data: {
    tables: [],
    detailAddress: [],
    selected: [],
    userID: null
  },

  onLoad: function () {
    let that = this;
    wx.getStorage({
      key: 'userID',
      success(res) {
        that.setData({
          userID: res.data
        }) 
      }
    });
    let userId = this.data.userID;
    if (userId == null) {
      userId = getApp().globalData.userID
    }
    wx.request({
      url: 'https://localhost:80/address/queryAllId/' + userId,
      header: {
        'content-type': 'application/json'
      },
      success (res) {
        console.log(res); 
        let Detail = [];
        let selected = [];
        for (let i = 0; i < res.data.length; i++)
        {
          Detail[i] = res.data[i].addrProvince + res.data[i].addrCity + res.data[i].addrArea + res.data[i].addrCommuity + res.data[i].addrDetail
          selected[i] = false
        }
        console.log(res.data);
        that.setData({
          tables: res.data,
          detailAddress: Detail,
          selected: selected
        })
      }
    });
  },

  handclick: function (e) {
    let number = e.currentTarget.dataset.index;
    let selected = [];
    for (let i = 0; i < this.data.selected.length; i++)
    {
      if (i == number) {
        selected[i] = true
      } else {
        selected[i] = false
      }
    }
    this.setData({
      selected: selected
    })
    let Url = '../orders/orders?num=' + number;
    wx.navigateTo({
      url: Url
    })
  },

  skipaddress (e) {
    let number = e.target.dataset.index;
    console.log(number);
    console.log(this.data.tables[number]);
    wx.navigateTo({
      url: "../editaddress/editaddress?data=" + JSON.stringify(this.data.tables[number]) + '&num=1'
    })
  },

  onUnload: function () {
    wx.redirectTo({
      url: '../orders/orders'
    })
  }
})